<html>
<head><meta charset="utf-8"><title>include_bytes! while compiling to wasm32-unknown-unknown · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html">include_bytes! while compiling to wasm32-unknown-unknown</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227268080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227268080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227268080">(Feb 22 2021 at 13:46)</a>:</h4>
<p>Hello all. Can anyone give me some advice on how to statically (at compile time) include bytes that I want to use in a function which will be called through web_assembly. The include_bytes macro does not seem to do the job. Thank you all in advance</p>



<a name="227268135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227268135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227268135">(Feb 22 2021 at 13:47)</a>:</h4>
<p>Why does <code>include_bytes!</code> not work?</p>



<a name="227268637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227268637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227268637">(Feb 22 2021 at 13:51)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink  [he/him]</span>  I do not know why it does not work. I am using the egui crate and when I compile natively I see the image I loaded, but when I compile to wasm and open it in my browser the image does not appear</p>



<a name="227268717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227268717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227268717">(Feb 22 2021 at 13:51)</a>:</h4>
<p>Do I need to allocate memory in wasm or something like that ?</p>



<a name="227268922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227268922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227268922">(Feb 22 2021 at 13:53)</a>:</h4>
<p>hmm, no, this should definitely work</p>



<a name="227268960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227268960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227268960">(Feb 22 2021 at 13:53)</a>:</h4>
<p>what data ends up in the binary? is there a difference in the actual bytes it results in?</p>



<a name="227269181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227269181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227269181">(Feb 22 2021 at 13:55)</a>:</h4>
<p>Is there a convenient way to check this? Or should I do a diff on the wasm binary after commenting out the line including the bytes?</p>



<a name="227269735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227269735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227269735">(Feb 22 2021 at 14:00)</a>:</h4>
<p>Print part of it to console?</p>



<a name="227269786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227269786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> panstromek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227269786">(Feb 22 2021 at 14:00)</a>:</h4>
<p>I use this macro in wasm and it works for me.   How do you try to load the image in the browser? I'd suspect the problem will be on JS/bindgen side here, rather than with the macro</p>



<a name="227270095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227270095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227270095">(Feb 22 2021 at 14:02)</a>:</h4>
<p><a href="/user_uploads/4715/rXii7t-IG-ZOKldCZFsQfw_5/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/rXii7t-IG-ZOKldCZFsQfw_5/image.png" title="image.png"><img src="/user_uploads/4715/rXii7t-IG-ZOKldCZFsQfw_5/image.png"></a></div>



<a name="227270212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227270212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227270212">(Feb 22 2021 at 14:03)</a>:</h4>
<p><a href="https://github.com/olivereanderson/waddle_allocator_frontend">https://github.com/olivereanderson/waddle_allocator_frontend</a></p>



<a name="227270276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227270276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227270276">(Feb 22 2021 at 14:04)</a>:</h4>
<p>this is my repository if you want to look through more of the code</p>



<a name="227270449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227270449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> panstromek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227270449">(Feb 22 2021 at 14:05)</a>:</h4>
<p>Does it crash if you replace unwrap_or_default with unwrap?</p>



<a name="227270754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227270754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227270754">(Feb 22 2021 at 14:07)</a>:</h4>
<p>Yes I think it crashes when I use unwrap. Look here: <a href="/user_uploads/4715/8S6qLD3O6Cc6r_8aMz7i0PSO/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/8S6qLD3O6Cc6r_8aMz7i0PSO/image.png" title="image.png"><img src="/user_uploads/4715/8S6qLD3O6Cc6r_8aMz7i0PSO/image.png"></a></div>



<a name="227270966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227270966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227270966">(Feb 22 2021 at 14:09)</a>:</h4>
<p>I am confused because in this tutorial: <a href="https://bfnightly.bracketproductions.com/chapter_21.html#loading-rex-assets">https://bfnightly.bracketproductions.com/chapter_21.html#loading-rex-assets</a> they seem to use two methods from an external crate to load an image statically into the wasm binary</p>



<a name="227271800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227271800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227271800">(Feb 22 2021 at 14:14)</a>:</h4>
<p>What appears to fail is not inclusion of the image into the binary (as suggested, consider printing parts of it, or maybe checksumming the data and printing out the checksum), but rather the decoding of the image.</p>



<a name="227273095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227273095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227273095">(Feb 22 2021 at 14:23)</a>:</h4>
<p>Is there a way to get the dbg! macro working when targeting wasm?</p>



<a name="227273535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227273535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> panstromek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227273535">(Feb 22 2021 at 14:25)</a>:</h4>
<p>Not dbg but you can import and use console.log. there's an example in wasm bindgen docs</p>



<a name="227273699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227273699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> panstromek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227273699">(Feb 22 2021 at 14:26)</a>:</h4>
<p>Try to also install console_error_panic_hook, that'll at least give you some backtrace</p>



<a name="227273785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227273785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> panstromek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227273785">(Feb 22 2021 at 14:26)</a>:</h4>
<p>There's also an example in wasm_bindgen docs (or wasm_pack, I keep confusing these two)</p>



<a name="227279359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227279359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227279359">(Feb 22 2021 at 15:03)</a>:</h4>
<p>Thanks. I managed to log the length of the bytes and it is indeed of the expected length. So <span class="user-mention" data-user-id="123586">@nagisa</span>  is right about decoding the image being the source of error.</p>



<a name="227281494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227281494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227281494">(Feb 22 2021 at 15:16)</a>:</h4>
<p>panicked at 'The global thread pool has not been initialized.: ThreadPoolBuildError { kind: IOError(Custom { kind: Other, error: "operation not supported on this platform" }) }</p>



<a name="227281871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227281871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227281871">(Feb 22 2021 at 15:19)</a>:</h4>
<p>Sounds like something in the program is trying to use threads. Does that crate have a <code>rayon</code> feature or something similar?</p>



<a name="227281977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227281977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227281977">(Feb 22 2021 at 15:20)</a>:</h4>
<p>Yes indeed it does. I think this is maybe coming from the image crate</p>



<a name="227282019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227282019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227282019">(Feb 22 2021 at 15:20)</a>:</h4>
<p><a href="https://github.com/image-rs/image/blob/master/Cargo.toml#L50">https://github.com/image-rs/image/blob/master/Cargo.toml#L50</a></p>



<a name="227282050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227282050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227282050">(Feb 22 2021 at 15:20)</a>:</h4>
<p>Is your image a JPEG?</p>



<a name="227282067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227282067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227282067">(Feb 22 2021 at 15:20)</a>:</h4>
<p>found someone with a similar problem here: <a href="https://radu-matei.com/blog/tensorflow-inferencing-wasi/">https://radu-matei.com/blog/tensorflow-inferencing-wasi/</a></p>



<a name="227282101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227282101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227282101">(Feb 22 2021 at 15:20)</a>:</h4>
<p>yes my image is a JPEG</p>



<a name="227282202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227282202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227282202">(Feb 22 2021 at 15:21)</a>:</h4>
<p>Yeah, try <code>default-features = false, features = ["jpeg"]</code></p>



<a name="227283138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/include_bytes%21%20while%20compiling%20to%20wasm32-unknown-unknown/near/227283138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Oliver E. Anderson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/include_bytes!.20while.20compiling.20to.20wasm32-unknown-unknown.html#227283138">(Feb 22 2021 at 15:27)</a>:</h4>
<p>That worked! Thank you all so much :) :) :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>